import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { CrudService } from 'src/shared/common/crud.service';
import { User } from './entities/user.entity';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { Public } from 'src/shared/auth/decorators/auth.decorator';
import { Limit } from 'src/shared/utils/pagination';
import { UpdateUserDto } from './dto/update-user.dto';

@Controller('user')
export class UserController {
  constructor(
    private readonly userService: UserService,
    private readonly crudService: CrudService<User>,
  ) {}

  @Post()
  @Public()
  create(@Body() createUserDto: CreateUserDto) {
    return this.crudService.create(createUserDto);
  }

  @Get()
  @Public()
  findAll(@Query() limit: Limit) {
    return this.userService.list(limit);
  }

  @Get(':id')
  @Public()
  findOne(@Param('id', new ParseIntPipe()) id: number) {
    return this.crudService.findOne(id, {});
  }

  @Patch(':id')
  @Public()
  update(
    @Param('id', new ParseIntPipe()) id: number,
    @Body() updateUserDto: UpdateUserDto,
  ) {
    return this.crudService.update(id, updateUserDto);
  }

  @Delete(':id')
  @Public()
  remove(@Param('id', new ParseIntPipe()) id: number) {
    return this.crudService.remove(id);
  }

  @Patch(':id/restore')
  @Public()
  restore(@Param('id', new ParseIntPipe()) id: number) {
    return this.crudService.restore(id);
  }
}
